/**
 * 日期格式化
 * @author webqkdnyfather
 * @param {String} time 
 * @returns String
 */

function dateDiff(time) {
    var d_minutes, d_hours, d_days, d;
    var nowTime = parseInt(new Date().getTime() / 1000);
    newTime = new Date(time).getTime() / 1000;
    d = nowTime - newTime;
    d_days = parseInt(d / 86400);
    d_hours = parseInt(d / 3600);
    d_minutes = parseInt(d / 60);
    if (d_days > 0 && d_days < 4) {
        return d_days + "天前";
    } else if (d_days <= 0 && d_hours > 0) {
        return d_hours + "小时前";
    } else if (d_hours <= 0 && d_minutes > 0) {
        return d_minutes + "分钟前";
    } else {
        return "刚刚";
    }
}
/**判断是否是微信浏览器
 * @author webqkdnyfather
 *  @param {String}
 */

function is_weixn() {
    var ua = navigator.userAgent.toLowerCase();
    if (ua.match(/MicroMessenger/i) == "micromessenger") {
        alert('return true');
    } else {
        alert('return false');
    }
}

/**判断PC还是移动端
 * @author webqkdnyfather
 *  @param {String}
 */
function ISM() {
    window.location.href = /Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent) ? "https://www.baidu.com/" :
        "http://news.baidu.com/";

}
/**
 * @author webqkdnyfather
 * @param {String} navigator.userAgent 形参描述
 */
function getRE() {
    var RenderingEngine = "";

    if (navigator.userAgent.indexOf("MSIE") > 0) {
        RenderingEngine = "MSIE";
    }
    if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) {
        RenderingEngine = "Firefox";
    }
    if (isSafari = navigator.userAgent.indexOf("Safari") > 0) {
        RenderingEngine = "Safari";
    }
    if (isCamino = navigator.userAgent.indexOf("Camino") > 0) {
        RenderingEngine = "Camino";
    }
    if (isMozilla = navigator.userAgent.indexOf("Gecko/") > 0) {
        RenderingEngine = "Gecko";
    }
    console.log(RenderingEngine);
}





/**图片懒加载
 * @author webqkdnyfather
 * @param {String}
 */

//函数 首次调用
/*监控网页高度 可见视口高度+滚动的高度
获取图片
遍历
判断*/
function lazyload() {
    //事件处理函数中 - 获取当前总可见内容高度 = 网页可见视口高度 + 滚动条滚动高度默认是0
    var temp1 = window.innerHeight || document.documentElement.clientHeight
    var temp2 = document.body.scrollTop || document.documentElement.scrollTop
    var maxShowHeight = temp1 + temp2
    var imgsObj = document.querySelectorAll('img') //获取图片
    imgsObj.forEach(function(item, index) { //遍历
        if (item.offsetTop < maxShowHeight) { //判断
            item.src = item.getAttribute('src-real')
        }
    })


}
lazyload()
window.onload = lazyload